<template>
 <lay-layout class="Pop">

  <lay-body  >
    <lay-form :model="model" ref="layFormRef" class="MainForm" >       
      <lay-form-item label="菜单代码" prop="Code" required  >
              <lay-input v-model="model.Code" disabled
              suffix-icon="layui-icon-search"
              @click="selPage"
              ></lay-input>
            </lay-form-item>
  <lay-form-item label="菜单名称" prop="Name" required>
              <lay-input v-model="model.Name" disabled
              @click="selPage"
              ></lay-input>

            </lay-form-item>
   
  <lay-form-item label="图标" prop="ImgUrl" >
          <lay-icon-picker v-model="model.ImgUrl" type="layui-icon-face-smile" page disabled></lay-icon-picker>
      
  </lay-form-item>
  <lay-form-item label="排序号" prop="SortNo" >
              <lay-input v-model="model.SortNo"></lay-input>
            </lay-form-item>
  <lay-form-item label="备注" prop="Memo" >
              <lay-input v-model="model.Memo"></lay-input>
            </lay-form-item>
  <lay-form-item label="参数1" prop="P1" >
              <lay-input v-model="model.P1"></lay-input>
            </lay-form-item>
  <lay-form-item label="参数2" prop="P2" >
              <lay-input v-model="model.P2"></lay-input>
            </lay-form-item>
  <lay-form-item label="参数3" prop="P3" >
              <lay-input v-model="model.P3"></lay-input>
            </lay-form-item>
  <lay-form-item label="参数4" prop="P4" >
              <lay-input v-model="model.P4"></lay-input>
            </lay-form-item>
          </lay-form>
    </lay-body>
    <lay-footer>
     
      <lay-button size="sm" type="primary" @click="toSubmit"
            >保存</lay-button
          >
          <lay-button size="sm" @click="toCancel" style="margin-left:40px;">取消</lay-button>
    </lay-footer>
  </lay-layout>

</template>

<script lang="ts">
import { ref, watch,reactive,onMounted,h } from 'vue'
import { layer } from '@layui/layer-vue'
import MyHttp from "../../library/MyHttp";  
import MyWin from "../../library/MyWin"; 
import MyPage from "../../library/MyPage"; 
import {MyExcel} from "../../library/MyExcel"; 
import {MySimpleExport,TableColumn} from "../../library/MySimpleExport"; 
import MyData from "../../library/MyData"; 
import selpage from "./selpage.vue";  

export default {
  props:{
      data:Object,
      isAdd:Boolean
  },

  setup(prop:any, context:any) {
    const baseUrl="/htmenu";
    const myWin=ref<any>(null);
    const model = reactive<any>(prop.data )
    console.info(model);
    const layFormRef = ref<any>()
    const toSubmit=async()=>{
      layFormRef.value.validate((isValidate:boolean, model:any, errors:Array<any>) => {
          if(!isValidate){
            let msg='';
            errors.forEach(element=>{ 
              msg+=`${element.message}
              `; 
            })
            
            MyWin.alert(msg,{});
            return;
          }
          save();
      });
    } 
    const toCancel=()=>{ 
      context.emit("cancel");  
      myWin.value.close();
    }
    const save=async()=>{
      let url=baseUrl+"/Insert";
      if(!prop.isAdd){
        url=baseUrl+"/update";
      }
      var r=await new MyHttp().post(url,model,
        { 
        }
      ); 
      context.emit("ok",model); 
      myWin.value.close();  
    }
    const selPage=async()=>{
        
      var opt={
          title: '选择菜单',
          content: h( selpage, 
            {   
             onOk:(data:any)=>{
              model.HTPage_Id=data.Id;
              model.Code=data.Code;
              model.Name=data.Name;
              model.ImgUrl=data.ImgUrl;
              model.Memo=data.Memo;
               
             }       
            }
            ), 
          area: ['1000px','700px'] 
        }; 
        myWin.value.open(opt ); 
    }
    
    
    onMounted(() =>{  
      myWin.value=new MyWin();
    });
    return {
      model,
      layFormRef,
      toSubmit,
      toCancel,

      selPage,
       

    }
  }
}
</script>
<style scoped>
.Pop .layui-footer,
.Pop .layui-header {
  height: 50px;
  text-align: center; 
  padding-top:10px;
}  
.Pop .layui-body{
  justify-content:start;
}
.MainForm{
  margin: 10px;   
  width:90%;
} 
.left 
{ 
  width: 400px;
}
.right{
  
  flex:1;
  
}
.w10{
  width:10px;
}
.right .TBMain{
  width:380px;
}
.right .layui-form-label{
  width:60px;
}
.right .layui-form-item{
  margin-bottom: 5px;
}

 
.Item{
  border-bottom:1px dashed var(--global-neutral-color-5) ;
  margin-top:10px;
}
.Item:hover  {
  box-shadow: 2px 2px 14px #ccc;
  cursor: pointer;
}
.Item:hover i{
  display: inline;
}
</style>